<%--
  Created by IntelliJ IDEA.
  User: de'l'l
  Date: 2021-04-16
  Time: 15:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
</head>
<body onload="loadData()">
<br>
<button type="button" class="btn-success" onclick="myPrice()">查看收入</button>
<span style="font-size: small">选择的收入为： </span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button type="button" class="btn-success" onclick="myCost()">查看成本</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button type="button" class="btn-success" onclick="myProfit()">查看利润</button>

<table class="table">
    <thead>
    <th><input type="checkbox" name="selectId" onclick="quanxuan(this)">全选</th>
    <th>点菜编号</th>
    <th>菜名</th>
    <th>是否付费</th>
    <th>菜的收入</th>
    <th>菜的成本</th>

    </thead>
    <tbody id="tb">

    </tbody>
</table>

<script>
    function loadData() {
        $.ajax({
            url: "${pageContext.request.contextPath}/table/moneyListAjax",
            type: "get",
            dataType: "json",

            success: function (data) {
                var html = "";
                for (var i = 0; i < data.info.length; i++) {
                    html += "<tr>" +
                        "<td><input  type=\"checkbox\" name=\"selectId\" value='" + data.info[i].tEId + "'></td>" +
                        "<td>" + data.info[i].tEId + "</td>" +
                        "<td>" + data.info[i].eName + "</td>" +
                        "<td>" + data.info[i].tECheck + "</td>" +
                        "<td>" + data.info[i].tEPrice + "</td>" +
                        "<td>" + data.info[i].tECost + "</td>" +
                        "</tr>"

                }
                $("#tb").html(html);

            }
        })
    }

    //全选
    function quanxuan(obj) {
        //获取全选的值
        var v = $(obj).prop("checked");
        $("input[name='selectId']").prop("checked", v);
        $("input[name='selectId']").prop("checked", $(obj).prop("checked"));
    }

    function myPrice() {
        var arrid = ""
        /*jquery伪类选择*/
        /* $("input[type='checkbox']:checked") 获取所有选中的复选框*/
        $("input[type='checkbox']:checked").each(function () {
            arrid += $(this).val() + ",";
        })
        $.ajax({
            url: "${pageContext.request.contextPath}/table/priceAjax",
            type: "get",
            data: {"arrId": arrid},
            dataType: "json",
            success: function (data) {
                console.log(data);
                alert(data.info);
                //刷新
                loadData();


            }
        })

    }

</script>

</body>
</html>
